﻿using EduAssess.Models;
using EduAssess.Services.Interfaces;

namespace EduAssess.Services;

public class TestService(
    IDialogService dialogService,
    PageNavigationService navigationService,
    Repository repository)
{
    public Test GetTest(Guid testId)
        => repository.FindAll<Test>().FirstOrDefault(x => x.Id == testId)!;

    public void SaveTest(Test? test)
    {
        test.CreationDate = DateTime.Now;
        repository.Save(test);
        dialogService.ShowMessage("Тест сохранен!");
        navigationService.GoBack();
    }

    public void DeleteTest(Guid testId)
    {
        repository.Delete<Test>(testId);
        dialogService.ShowMessage("Тест удален!");
        navigationService.GoBack();
    }
}